package mock

import "context"

/*
1. gomock 测试业务逻辑  mock仓储层 接口
安装：
	go get -u github.com/golang/mock/gomock

	go install github.com/golang/mock/mockgen@latest

生成接口的mock实现：
	 mockgen -source user.go -package=mock -destination=./mock/user.go

*/

/*
2. go-sqlmock mock db 数据，gorm
安装：
	go get github.com/DATA-DOG/go-sqlmock
*/

/*
写接口使用mockgen工具生成mock：
	fake 测试
	grpc 服务， rocketmq， kafka，
*/

type User struct {
	Mobile   string
	Password string
	NickName string
}

type UserServer struct {
	Db UserData
}

func (us *UserServer) GetUserByMobile(ctx context.Context, mobile string) (User, error) {
	user, err := us.Db.GetUserByMobile(ctx, mobile)
	if err != nil {
		return User{}, err
	}
	if user.NickName == "bobby18" {
		user.NickName = "bobby17"
	}
	return user, nil
}

// 仓储层接口

type UserData interface {
	GetUserByMobile(ctx context.Context, mobile string) (User, error)
}
